package com.lqw.vhr.service;

import com.lqw.vhr.mapper.EmployeeEcMapper;
import com.lqw.vhr.model.EmployeeEc;
import com.lqw.vhr.model.RespPageBean;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Date;
import java.util.List;

@Service
public class EmployEcService {

    @Autowired
    EmployeeEcMapper employeeEcMapper;

    public RespPageBean getEmpEcByPage(Integer page, Integer size, String keyword) {
        if (page != null && size != null) {
            page = (page - 1) * size;
        }
        List<EmployeeEc> empEcByPage = employeeEcMapper.getEmpEcByPage(page, size, keyword);
        long total = employeeEcMapper.countEmpEcByPage(page, size, keyword);
        RespPageBean respPageBean = new RespPageBean();
        respPageBean.setData(empEcByPage);
        respPageBean.setTotal(total);
        return respPageBean;
    }

    public int updateEmpEc(EmployeeEc empEc) {
        return employeeEcMapper.updateByPrimaryKeySelective(empEc);
    }

    public int addEmpEc(EmployeeEc empEc) {
        empEc.setEcDate(new Date(System.currentTimeMillis()));
        return employeeEcMapper.insertSelective(empEc);
    }

    public int deleteEmpEcByEid(Integer id) {
        return employeeEcMapper.deleteByPrimaryKey(id);
    }
}
